//
//  HBCategoryModel.m
//  HeartBeat
//
//  Created by karong on 2023/8/29.
//

#import "HBCategoryModel.h"

@implementation HBCategory
- (id)copyWithZone:(NSZone *)zone {
    HBCategory * object = [HBCategory new];
    object.category = self.category;
    object.word_type = self.word_type;
    object.pay_type = self.pay_type;
    object.finish_type = self.finish_type;
    object.channelType = self.channelType;
    return object;
}

@end
@implementation HBCategoryModel
+ (NSDictionary *)mj_objectClassInArray {
    return @{@"category":NSClassFromString(@"HBCategoryItemModel"),
             @"word_type":NSClassFromString(@"HBCategoryItemModel"),
             @"pay_type":NSClassFromString(@"HBCategoryItemModel"),
             @"finish_type":NSClassFromString(@"HBCategoryItemModel"),
             @"sort_type":NSClassFromString(@"HBCategoryItemModel")};
}

- (NSArray *)arrayWithSection:(NSInteger)section {
    NSArray * array = @[];
    if (section == 0) {
        array = self.category;
    }
    else if (section == 1) {
        array = self.finish_type;
    }
    else if (section == 2) {
        array = self.pay_type;
    }
    else if (section == 3) {
        array = self.word_type;
    }
    return array;
}

- (void)didSelectIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        self.selectCategory.category = self.category[indexPath.row];
        [HBEvenManager event:@"Discovery_channel" evenLogType:(HBEvenLogType_Click) attributes:@{@"category_name":KEmptyStr(self.selectCategory.category.title)}];
    }
    else if (indexPath.section == 1) {
        self.selectCategory.finish_type = self.finish_type[indexPath.row];
        [HBEvenManager event:@"Discovery_channel" evenLogType:(HBEvenLogType_Click) attributes:@{@"category_name":KEmptyStr(self.selectCategory.finish_type.title)}];
    }
    else if (indexPath.section == 2) {
        self.selectCategory.pay_type = self.pay_type[indexPath.row];
        [HBEvenManager event:@"Discovery_channel" evenLogType:(HBEvenLogType_Click) attributes:@{@"category_name":KEmptyStr(self.selectCategory.pay_type.title)}];
    }
    else if (indexPath.section == 3) {
        self.selectCategory.word_type = self.word_type[indexPath.row];
        [HBEvenManager event:@"Discovery_channel" evenLogType:(HBEvenLogType_Click) attributes:@{@"category_name":KEmptyStr(self.selectCategory.word_type.title)}];
    }
}

- (BOOL)isSelectIndexPath:(NSIndexPath *)indexPath {
    BOOL rec = NO;
    if (indexPath.section == 0) {
        rec = self.selectCategory.category == self.category[indexPath.row];
    }
    else if (indexPath.section == 1) {
        rec = self.selectCategory.finish_type == self.finish_type[indexPath.row];
    }
    else if (indexPath.section == 2) {
        rec = self.selectCategory.pay_type == self.pay_type[indexPath.row];
    }
    else if (indexPath.section == 3) {
        rec = self.selectCategory.word_type == self.word_type[indexPath.row];
    }
    return rec;
}

- (HBCategory *)selectCategory {
    if (!_selectCategory) {
        _selectCategory = [HBCategory new];
    }
    if (!_selectCategory.category && self.category.count > 0) {
        _selectCategory.category = self.category.firstObject;
    }
    if (!_selectCategory.finish_type && self.finish_type.count > 0) {
        _selectCategory.finish_type = self.finish_type.firstObject;
    }
    if (!_selectCategory.pay_type && self.pay_type.count > 0) {
        _selectCategory.pay_type = self.pay_type.firstObject;
    }
    if (!_selectCategory.word_type && self.word_type.count > 0) {
        _selectCategory.word_type = self.word_type.firstObject;
    }
    return _selectCategory;
}
@end
@implementation HBCategoryItemModel

@end
